package com.zero.rabbitmq.confirm;

import com.rabbitmq.client.*;
import com.zero.rabbitmq.utils.ConnectionUtil;

import java.io.IOException;

public class Customer {

    private final static String QUEUE_NAME = "ORIGIN_QUEUE";

    public static void main(String[] args) {

        try {
            Connection connection = ConnectionUtil.getConnection();
            Channel channel = connection.createChannel();
            /**
             * String exchange,
             * String type,
             * boolean durable,
             * boolean autoDelete,
             * Map<String, Object> arguments
             */
            //声明队列
            channel.queueDeclare(QUEUE_NAME,false,false,false,null);
            //创建消费者
            Consumer consumer = new DefaultConsumer(channel) {
                @Override
                public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                    String msg = new String(body, "UTF-8");
                    System.out.println("Received message: " + msg);
                    System.out.println("consumerTag: " + consumerTag);
                    System.out.println("DeliveryTag: " + envelope.getDeliveryTag());
                }
            };

            //开始获取消息
            channel.basicConsume(QUEUE_NAME,true,consumer);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
